package pro.softzhang.algo.lc1400;

public class LC1460_MakeTwoArraysEqualByReversingSubArrays {
    public static void main(String[] args) {
        int[] target = {1, 2, 3, 4}, arr = {2, 4, 1, 3};
        boolean can = new LC1460_MakeTwoArraysEqualByReversingSubArrays().canBeEqual(target, arr);
        System.out.println(can);
    }

    public boolean canBeEqual(int[] target, int[] arr) {
        int[] flags = new int[4];
        int total = 0;
        for (int i = 0; i < target.length; i++) {
            if(++flags[target[i]] == 1) {
                total++;
            }
            if(--flags[arr[i]] == 0) {
                total--;
            }
        }
        return total == 0;
    }
}
